package com.hktf.corelib.utils;

/**
 * Created by Administrator on 2016/9/21.
 */
public class HandleStringUtils {
    /**
     * 处理text文本的回车换行符
     * @param text
     * @return
     */
    public static String handleTextFormat(String str){
        if(str==null){
            return null;
        }
        if (str.contains("\r\n")) {
            str =  str.replace("\r\n", "\n");
        } else if (str.contains("\\r\\n")) {
            str  = str.replace("\\r\\n", "\n");
        } else if (str.contains("/r/n")){
            str  =str.replace("/r/n", "\n");
        }else if(str.contains("\\n")){
            str =  str.replace("\\n", "\n");
        }
        return str;
    }

    //处理配置中路径所用/配置成\
    public static String handlePathFormat(String str){
        if(str==null){
            return null;
        }
        if (str.contains("\\")) {
            str =  str.replace("\\", "/");
        }
        return str;
    }

    //clientStr clientname   hideStr project_hide
    public static boolean handleStringEqualize(String clientStr,String hideStr){

        if(clientStr == null || hideStr == null){
            return false;
        }
        String strNumber = clientStr.substring(0,clientStr.lastIndexOf("-"));
        //去掉所有的空格
        String newHideStr = hideStr.replace(" ", "");
        String[] strArray = newHideStr.split(",");

        for(int i = 0; i < strArray.length; i++){
            if(strArray[i].toUpperCase().contains("ANDROID") && strArray[i].equalsIgnoreCase(clientStr)){
                return true;
            }else {
                if (strArray[i].equalsIgnoreCase(strNumber)){
                    return true;
                }
            }
        }
        return false;
    }

}
